package com.example.baidu.speech.realtime.service.impl;

import com.example.baidu.speech.realtime.dto.BaiduSpeechRealtimeDTO;
import com.example.baidu.speech.realtime.sdk.connection.Runner;
import com.example.baidu.speech.realtime.service.BaiduSpeechRealtimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class BaiduSpeechRealtimeServiceImpl implements BaiduSpeechRealtimeService {

    @Override
    public void recognizingRealtimeSpeech(BaiduSpeechRealtimeDTO baiduSpeechRealtimeDTO) {
        try {
            // 调用 原生的百度实时语音识别API 识别语音内容
            (new Runner(baiduSpeechRealtimeDTO.getInputStream(), Runner.MODE_REAL_TIME_STREAM)).run(baiduSpeechRealtimeDTO.getWebSocketId());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new RuntimeException("百度实时语音识别失败");
        }
    }

}
